package com.tools.app.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.hm.base.android.mob.AMApplication;
import com.hm.base.android.mob.util.MConstants;
import com.hm.base.android.mob.util.network.NetWorkInfoParser;
import com.tools.app.AppApplication;

/**
 * Created by ChenLi on 2018/1/2.
 */

public class BootReceiver extends BroadcastReceiver {

    private int currNetType = MConstants.NONE_ID;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) {
            //网络状态变化、开屏、用户解锁，需要解析一遍网络。
            NetWorkInfoParser.isNetConnect(AMApplication.getInstance());

            ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();

            AppApplication application = (AppApplication) AMApplication.getInstance();
            if (application != null && netInfo != null && currNetType != netInfo.getType()) {
                // application.handleMobEmptyMessage(R.id.msg_news_network_status_changed);
                currNetType = netInfo.getType();
            }

            if (netInfo != null && netInfo.isAvailable()) {
                if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                    /////WiFi网络
                } else if (netInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                    //移动网络 2g 3g
                }
            } else {
                //网络断开
            }
        } else if (intent.getAction().equals("com.swipe.CLOSE_EMPTY")) {
            //swipe关闭
        }
    }
}
